package com.view;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.controller.UserManager;

@SuppressWarnings("serial")
public class RegisterUserServlet extends HttpServlet{
	private UserManager userManager = new UserManager();
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String userName = req.getParameter("txt_Username");
		String userPassword = req.getParameter("txt_Password");
		String emailAddress = req.getParameter("txt_mailAddress");
		Date registryDate = new Date();
		
		boolean userRegistered = userManager.registerUser(userName, userPassword, emailAddress, registryDate);
		
		if(userRegistered){
			resp.sendRedirect("/index.jsp?registered=true");
		}else{
			resp.sendRedirect("/index.jsp?registered=false");
		}
	}
	
}
